package com.js.rtu.fragment.third;

import android.os.Bundle;
import android.widget.LinearLayout;

import androidx.core.widget.NestedScrollView;

import com.js.rtu.R;
import com.js.rtu.base.BaseFragment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.OnClick;


public class DebugWriteFragment extends BaseFragment {


    @BindView(R.id.ll_debug)
    LinearLayout llDebug;
    @BindView(R.id.scrollView)
    NestedScrollView scrollView;
    public static DebugWriteFragment newInstance() {
        Bundle args = new Bundle();
        DebugWriteFragment fragment = new DebugWriteFragment();
        fragment.setArguments(args);


        return fragment;
    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_tab_third_debug_write;
    }

    @Override
    protected void initView() {
        EventBus.getDefault().register(this);
    }


    @OnClick(R.id.tv_clean)
    public void onViewClicked() {
        llDebug.removeAllViews();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
    }

    /**
     * 发送过的指令
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void receive(DebugWriteBean bean) {
        add(bean.getCmd(), llDebug);
        scrollView.scrollTo(0,0);
    }


}
